<?php

namespace App\Modules\Admin\Http\Requests\Expenses;

use App\Modules\Admin\Entities\Expenses\MasterModel;
use App\Modules\Admin\Http\Requests\BaseRequest;

class MasterRequest extends BaseRequest
{
    public function setInstance()
    {
        $this->instance = MasterModel::getInstance();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'community_id'   => ['required'],
            'apparatus_id'   => ['required'],
            'master_name' => [
                'required',
                'max:256',
                'unique:' . $this->instance->getTable() . ',master_name' . $this->validate_id
            ],
            'master_sn' => [
                'required',
                'max:256',
                'unique:' . $this->instance->getTable() . ',master_sn' . $this->validate_id
            ],
            'price'   => ['required'],
        ];
    }

    public function messages()
    {
        return [
            'community_id.required' => '请选择片区！',
            'apparatus_id.required' => '请选中水机！',
            'master_name.required' => '请输入仪表名称！',
            'master_name.max'      => '仪表名称字数不可超过 256！',
            'master_name.unique'   => '仪表名称已存在，请更换！',
            'master_sn.required' => '请输入仪表编码！',
            'master_sn.max'      => '仪表编码字数不可超过 256！',
            'master_sn.unique'   => '仪表编码已存在，请更换！',
            'price.required' => '请输入仪表单价！',
        ];
    }
}
